﻿package app.demo.MyTouchApp{
 
    import flash.events.TUIO; // allows to connect to touchlib/tbeta
 
    import flash.display.*;
    import flash.events.*;
	import flash.events.MouseEvent;
    import flash.geom.*; // needed for curPt;
	import flash.display.SimpleButton;
	import flash.net.URLRequest;
	import flash.display.FrameLabel;
	import fl.controls.Label;
	import fl.controls.Button;
	import fl.controls.*;
	import fl.core.*;
	import flash.display.Sprite;
	import flash.text.*;
	import flash.system.fscommand;
	import flash.system.*;
	import flash.utils.getTimer;
	import flash.utils.Timer;
	import fl.transitions.easing.*;
	import flash.media.*;
	//import Math.abs;
 
     public class shapesGameP2 extends MovieClip {
 
        private var color:uint = 0xff0000; // color of lines
        private var thickness:Number = 30; // thickness of lines
        private var blobs:Array = new Array(); // blobs we are currently interacting with
        private var lines:Array = new Array(); // array to hold the lines
		private var numButtonWidth:Number = 100;
		private var numButtonHeight:Number = 50;
		
		var movie1:MovieClip = new MovieClip();
		var myTextFormat1:TextFormat = new TextFormat();
		
		private var avatars:Array = ["av11.png", "av22.png", "av33.png", "av44.png","av55.png","av66.png","av77.png","av88.png","av99.png","av100.png"];
		
		private var images:Array = ["darkBackground.png","av1.jpg", "shapesTitle.png","mute.png","unmute.png"];
		
		private var pics:Array = ["arr.png","dro.png","mo.png","shapee.png","h.png","trianglee.png","treee.png", "spadee.png"];
								  //,"8.png","9.png",
								  //"10.png","11.png","111.png","222.png","333.png", "1000.png","1100.png"];
		
		private var pics2:Array = ["arr.png","dro.png","mo.png","shapee.png","h.png","trianglee.png","treee.png", "spadee.png"];
		
		private var picsInHole:Array=new Array(10);
		
		var iLoaders:Array = new Array (pics.length);
		var iLoaders2:Array = new Array (pics2.length);
		
		var position:Array = new Array(pics.length*2);
		var position2:Array = new Array(pics2.length*2);
		
		var iHoles:Array=new Array(10);
		var pictures:Array = new Array (10);
		
		var backpst:int=100;
		var backpst2:int=100;
		public var identity:Number = 0;
		var newTouchItem:Array = new Array();
		var doubleT:Timer = new Timer(500);
		
		var trialimg:Loader= new Loader();
		var hexa:Loader= new Loader();
		var triangle:Loader= new Loader();
		var star:Loader= new Loader();
		var circle:Loader= new Loader();
		var squaree:Loader= new Loader();
		var moon:Loader= new Loader();
		var star2:Loader= new Loader();
	
		var imageBack:Loader = new Loader();
		var avatarP1:Loader = new Loader();
		var avatarP2:Loader = new Loader();
		var topicL:Label = new Label();
		var player:Label = new Label();
		var player2:Label = new Label();
		
		var mainLoader:Loader = new Loader();
		var mainLoader1:Loader = new Loader();
		var mainLoader2:Loader = new Loader();
		var mainLoader3:Loader = new Loader();
		var mainLoader4:Loader = new Loader();
		var mainLoader5:Loader = new Loader();
		
		var imageX:Loader = new Loader();
		var imageX1:Loader = new Loader();
		var topic:Loader = new Loader();
		var board:Loader = new Loader();
		var noSound:Boolean=false;
		
		public var buttonBack:Button;
		public var buttonExit:Button;
		public var buttonDone:Button;
		public var buttonDone2:Button;
		public var skipTurn1:Button;
		public var skipTurn2:Button;
		public var skipTurnFlag:int=0;
		
		
		var skipp:Button = new Button();
		var skipp1:Button = new Button();
		var skipp2:Button = new Button();
		var skipp3:Button = new Button();
		var skipp4:Button = new Button();
		var skipp5:Button = new Button();
		
		var square:Sprite = new Sprite();
		
		var sLabel1:Label=new Label();
		var sLabel2:Label=new Label();
		var score1:Label=new Label();
		var score2:Label=new Label();
		
		var sp1:int=0;
		var sp2:int=0;
		
		
		var myMaster:master;
		
		var skip2:Boolean = false;
		var skip7:Boolean = false;
		
		var errorSound:Sound;
		var correctSound:Sound;
		var mute:Loader  = new Loader();
		
		var FirstPoint:Point;
		var SecondPoint:Point;
		
		var gIndex:int=100;
		var gIndex2:int=100;
		var myTimerC:Timer = new Timer(2000);
		var myTimerI:Timer = new Timer(2000);
		
		var myTimer2C:Timer = new Timer(2000);
		var myTimer2I:Timer = new Timer(2000);
		
		var myTimerFlash:Timer = new Timer(500);
		var myTimerFlash2:Timer = new Timer(500);
		
		///////////////////Extra Variables//////////////////////
		//var played:Boolean=false;
		var once:Boolean=true;
		var once2:Boolean=true;
		
		var turn:int=1;
  		
		var right:Loader = new Loader();
		var wrong:Loader = new Loader();
		
		var bmpimages:Array = new Array();
		var bmpimages2:Array = new Array();
		
		var bound:Sprite= new Sprite();
		var bound2:Sprite= new Sprite();
		
		public var bringToFront:Boolean = true;
		public var mouseSelection = false;
		public var xdist:Number;
		public var ydist:Number;
		public var distance:Number;
		private var oldX:Number = 0;
		private var oldY:Number = 0;		
		public var lastClick:Number = 0;
		public var clickRadius:Number = 50;		
		
		var pleft:int=8;
		var leftLabel:Label = new Label();
		
		
	
		var indication:int;
		
		
		
		////////////////////////////////////////////////////////
		
		public function shapesGameP2(m:master):void {
		
		TUIO.init(this,'localhost',3000,'',true);
        trace("MyTouchApp Initialized");
		myMaster=m;
		addChild(movie1);
		
		//addEventListener(TouchEvent.MOUSE_DOWN, downEvent, false, 0, true); // run when finger down
        addEventListener(TouchEvent.MOUSE_UP, upEvent, false, 0, true); // run when finger up
        addEventListener(Event.ENTER_FRAME, updater, false, 0, true); // keep running
		//start();
		
		myTimerFlash.addEventListener(TimerEvent.TIMER, flashing);
		myTimerFlash2.addEventListener(TimerEvent.TIMER, flashing2);
		
		// mute buttons////
		
		
			mute.load(new URLRequest(images[4]));
			mute.name='unmute';
			mute.x=1024;
			mute.y=400;
			mute.rotationZ=90;
			mute.scaleX=0.2;
			mute.scaleY=0.2;
			mute.addEventListener(TouchEvent.MOUSE_DOWN,muteMethod);
		
		
		
		//////////////////////
		
		
		
		
		imageBack.load(new URLRequest(images[0]));
		imageBack.scaleX=1.4;
		//imageBack.scaleY=0.8;
		movie1.addChild(imageBack);
		
		myTextFormat1.font = "Kristen ITC";
		myTextFormat1.size = 70;
		
		
		topicL.text = "Transportation";
		topicL.width=600;
		topicL.height=300;
		topicL.x=260;
		topicL.visible=true;
		topicL.setStyle("textFormat", myTextFormat1);
		//movie1.addChild(topicL);
		
		topic.load(new URLRequest(images[2]));
		topic.x=350;
		topic.y=0;
		topic.scaleX=1.2;
		topic.scaleY=1.1;
		//movie1.addChild(topic);
		
		
		buttonBack = new Button();
		buttonBack.label="BACK";
		//buttonBack.x=200;
		buttonBack.y=400;
		buttonBack.width=100;
		buttonBack.height=40;
		buttonBack.rotationZ=-90;
		//buttonBack.emphasized=true;
		buttonBack.addEventListener(TouchEvent.MOUSE_DOWN,backMethod);
		movie1.addChild(buttonBack);
		
		skipTurn1 = new Button();
		skipTurn1.label="SKIP TURN";
		skipTurn1.x=40;
		skipTurn1.y=465;
		skipTurn1.width=110;
		skipTurn1.height=30;
		skipTurn1.addEventListener(TouchEvent.MOUSE_DOWN,skipping);
		movie1.addChild(skipTurn1);
		
		skipTurn2 = new Button();
		skipTurn2.label="SKIP TURN";
		skipTurn2.x=1010;
		skipTurn2.y=240;
		skipTurn2.width=110;
		skipTurn2.height=30;
		skipTurn2.rotationZ=180;
		skipTurn2.alpha=0.5;
		skipTurn2.addEventListener(TouchEvent.MOUSE_DOWN,skipping1);
		movie1.addChild(skipTurn2);
		
		
		/*****************/
			
			/*imageX.load(new URLRequest(images[2]));
			imageX.x=975;
			imageX.y=16;
			imageX.alpha=0.0;
			imageX.addEventListener(TouchEvent.MOUSE_DOWN,disappear);
			movie1.addChild(imageX);
			
			
			imageX1.load(new URLRequest(images[2]));
			imageX1.x=975;
			imageX1.y=170;
			imageX1.alpha=0.0;
			imageX1.addEventListener(TouchEvent.MOUSE_DOWN,disappear1);
			movie1.addChild(imageX1);*/
			
		//mainLoader= new Loader();
			var url = new URLRequest("example4shapes.swf"); 
			mainLoader.load(url);
			mainLoader.y=520;
			mainLoader.x=840;
			movie1.addChild(mainLoader);
			
			
			skipp.label="Skip All Tips";
			skipp.addEventListener(TouchEvent.MOUSE_DOWN, skip3); 
			skipp.y=664;
			skipp.x=858;
			skipp.width=130;
			skipp.name="tip1";
			movie1.addChild(skipp);
			
			//mainLoader= new Loader();
			var url1 = new URLRequest("example2shapes.swf"); 
			mainLoader2.load(url1);
			mainLoader2.y=520;
			mainLoader2.x=840;
			mainLoader2.visible=false;
			movie1.addChild(mainLoader2);
			//mainLoader2.addEventListener(TouchEvent.MOUSE_DOWN,moveTip2);
			
			skipp2.label="Skip All Tips";
			//skipp2.addEventListener(TouchEvent.MOUSE_DOWN, skip4); 
			skipp2.y=675;
			skipp2.x=862;
			skipp2.width=130;
			skipp2.name="tip3";
			skipp2.visible=false;
			movie1.addChild(skipp2);
			
			//mainLoader= new Loader();
			var url2 = new URLRequest("example3shapes.swf"); 
			mainLoader1.load(url2);
			mainLoader1.y=480;
			mainLoader1.x=840;
			mainLoader1.visible=false;
			movie1.addChild(mainLoader1);
			
			
			skipp1.label="Skip All Tips";
			skipp1.addEventListener(TouchEvent.MOUSE_DOWN, skip4); 
			skipp1.y=675;
			skipp1.x=862;
			skipp1.width=130;
			skipp1.name="tip2";
			skipp1.visible=false;
			movie1.addChild(skipp1);
			
			
			

			
		/*****************/
		
		
		/******************************* TIPS PLAYER 2 **********/
		
		//mainLoader= new Loader();
			var url3 = new URLRequest("example4shapes2.swf"); 
			mainLoader3.load(url3);
			mainLoader3.y=200;
			mainLoader3.x=190;
			mainLoader3.rotationZ=180;
			movie1.addChild(mainLoader3);
			
			
			skipp3.label="Skip All Tips";
			skipp3.addEventListener(TouchEvent.MOUSE_DOWN, skip5); 
			skipp3.y=60;
			skipp3.x=170;
			skipp3.width=130;
			skipp3.rotationZ=180;
			skipp3.name="tip4";
			movie1.addChild(skipp3);
			
			
			//mainLoader= new Loader();
			var url4 = new URLRequest("example3shapes2.swf"); 
			mainLoader4.load(url4);
			mainLoader4.y=230;
			mainLoader4.x=170;
			mainLoader4.rotationZ=180;
			mainLoader4.visible=false;
			movie1.addChild(mainLoader4);
			
			
			skipp4.label="Skip All Tips";
			skipp4.addEventListener(TouchEvent.MOUSE_DOWN, skip6); 
			skipp4.y=30;
			skipp4.x=150;
			skipp4.width=130;
			skipp4.rotationZ=180;
			skipp4.name="tip5";
			skipp4.visible=false;
			movie1.addChild(skipp4);
			
			
			//mainLoader= new Loader();
			var url5 = new URLRequest("example2shapes2.swf"); 
			mainLoader5.load(url5);
			mainLoader5.y=210;
			mainLoader5.x=190;
			mainLoader5.rotationZ=180;
			mainLoader5.visible=false;
			movie1.addChild(mainLoader5);
			//mainLoader5.addEventListener(TouchEvent.MOUSE_DOWN,moveTip3);
			
			skipp5.label="Skip All Tips";
			//skipp2.addEventListener(TouchEvent.MOUSE_DOWN, skip4); 
			skipp5.y=60;
			skipp5.x=170;
			skipp5.width=130;
			skipp5.rotationZ=180;
			skipp5.name="tip6";
			skipp5.visible=false;
			movie1.addChild(skipp5);
			
			
			

			
		/*****************/
		
		buttonDone = new Button;
		buttonDone.x=870;
		buttonDone.y=570;
		buttonDone.width=120;
		buttonDone.height=40;
		buttonDone.label="SHOW TIPS";
		//buttonDone.enabled=false;
		buttonDone.addEventListener(TouchEvent.MOUSE_DOWN,showTips);
		movie1.addChild(buttonDone);
		buttonDone.visible=false;
		
		buttonDone2 = new Button;
		buttonDone2.x=170;
		buttonDone2.y=150;
		buttonDone2.width=120;
		buttonDone2.height=40;
		buttonDone2.rotationZ=180;
		buttonDone2.label="SHOW TIPS";
		//buttonDone.enabled=false;
		buttonDone2.addEventListener(TouchEvent.MOUSE_DOWN,showTips2);
		movie1.addChild(buttonDone2);
		buttonDone2.visible=false;
			
			
		
		
		buttonExit = new Button;
		buttonExit.x=1024;
		buttonExit.y=270;
		buttonExit.width=100;
		buttonExit.height=40;
		buttonExit.rotationZ=90;
		buttonExit.label="EXIT";
		buttonExit.addEventListener(TouchEvent.MOUSE_DOWN,closeApp);
		movie1.addChild(buttonExit);
		
		picsInHole[0]=new Loader();
		picsInHole[0].load(new URLRequest("arrHH.png"));
		picsInHole[0].x=550;
		picsInHole[0].y=360;
		
		picsInHole[1]=new Loader();
		picsInHole[1].load(new URLRequest("droHH.png"));
		picsInHole[1].x=430;
		picsInHole[1].y=320;
		
		picsInHole[2]=new Loader();
		picsInHole[2].load(new URLRequest("moHH.png"));
		picsInHole[2].x=650;
		picsInHole[2].y=280;
		
		picsInHole[3]=new Loader();
		picsInHole[3].load(new URLRequest("shapeeHH.png"));
		picsInHole[3].x=100;
		picsInHole[3].y=310;
		
		picsInHole[4]=new Loader();
		picsInHole[4].load(new URLRequest("hHH.png"));
		picsInHole[4].x=300;
		picsInHole[4].y=270;
		
		picsInHole[5]=new Loader();
		picsInHole[5].load(new URLRequest("triangleeHH.png"));
		picsInHole[5].x=210;
		picsInHole[5].y=370;
		
		picsInHole[6]=new Loader();
		picsInHole[6].load(new URLRequest("treeeHH.png"));
		picsInHole[6].x=850;
		picsInHole[6].y=280;
		
		picsInHole[7]=new Loader();
		picsInHole[7].load(new URLRequest("spadeeHH.png"));
		picsInHole[7].x=750;
		picsInHole[7].y=360;
		
		
		square.graphics.lineStyle(3,0x000000);
		square.graphics.beginFill(0xFFFFFF);
		square.graphics.drawRect(0,0,650,400);
		//square.graphics.endFill();
		square.x=200;
		square.y=100;
		//movie1.addChild(square);
		
		board.load(new URLRequest("boardPlayers.png"));
		board.x=40;
		board.y=245;
		movie1.addChild(board);
		
		//CIRCLE at index 0:
		pictures[0]=new Array(2);
		pictures[0][0]=550;
		pictures[0][1]=360;
		
		//SQUARE at index 1:
		pictures[1]= new Array (2);
		pictures[1][0]=430;
		pictures[1][1]=320;
		
		//HEXA at index 2:
		pictures[2]= new Array (2);
		pictures[2][0]=650;
		pictures[2][1]=280;
		
		//TRIANGLE at index 3:
		pictures[3]= new Array (2);
		pictures[3][0]=100;
		pictures[3][1]=310;
		
		//HEART at index 4:
		pictures[4]= new Array (2);
		pictures[4][0]=300;
		pictures[4][1]=270;
		
		//STAR at index 5:
		pictures[5]= new Array (2);
		pictures[5][0]=210;
		pictures[5][1]=370;
		
		pictures[6]= new Array (2);
		pictures[6][0]=850;
		pictures[6][1]=280;
		
		pictures[7]= new Array (2);
		pictures[7][0]=750;
		pictures[7][1]=360;
		
		iHoles[4]=new Loader();
		iHoles[4].load(new URLRequest("hHole.png"));
		iHoles[4].x=300;
		iHoles[4].y=270;
		//trialimg.rotationZ=30;
		//imageBack.scaleY=0.8;
		movie1.addChild(iHoles[4]);
		
		iHoles[3]=new Loader();
		iHoles[3].load(new URLRequest("shapeeHole.png"));
		iHoles[3].x=100;
		iHoles[3].y=310;
		movie1.addChild(iHoles[3]);
		
		iHoles[5]=new Loader();
		iHoles[5].load(new URLRequest("triangleeHole.png"));
		iHoles[5].x=210;
		iHoles[5].y=370;
		movie1.addChild(iHoles[5]);
		
		iHoles[6]=new Loader();
		iHoles[6].load(new URLRequest("treeeHole.png"));
		iHoles[6].x=850;
		iHoles[6].y=280;
		movie1.addChild(iHoles[6]);
		
		iHoles[1]=new Loader();
		iHoles[1].load(new URLRequest("droHole.png"));
		iHoles[1].x=430;
		iHoles[1].y=320;
		movie1.addChild(iHoles[1]);
		
		iHoles[0]=new Loader();
		iHoles[0].load(new URLRequest("arrHole.png"));
		iHoles[0].x=550;
		iHoles[0].y=360;
		movie1.addChild(iHoles[0]);
		
		iHoles[2]=new Loader();
		iHoles[2].load(new URLRequest("moHole.png"));
		iHoles[2].x=650;
		iHoles[2].y=280;
		movie1.addChild(iHoles[2]);
		
		iHoles[7]=new Loader();
		iHoles[7].load(new URLRequest("spadeeHole.png"));
		iHoles[7].x=750;
		iHoles[7].y=360;
		movie1.addChild(iHoles[7]);
		
		avatarP1.load(new URLRequest(avatars[myMaster.getIndexP1()]));
		avatarP1.x=20;
		avatarP1.y=500;  //530
		avatarP1.scaleX=1.1;
		avatarP1.scaleY=1.1;
		//avatar.addEventListener(TouchEvent.MOUSE_DOWN,dimMethod1);
		movie1.addChild(avatarP1);
		
		avatarP2.load(new URLRequest(avatars[myMaster.getIndexP2()]));
		avatarP2.x=1024;
		avatarP2.y=210; //180
		//avatarP2.y=530;
		avatarP2.scaleX=1.1;
		avatarP2.scaleY=1.1;
		avatarP2.rotationZ=180;
		avatarP2.alpha=0.5;
		//avatar.addEventListener(TouchEvent.MOUSE_DOWN,dimMethod1);
		movie1.addChild(avatarP2);
		
		
		movie1.addChild(mute);
		
		//avatar.addEventListener(TouchEvent.MOUSE_DOWN,dimMethod1);
		
		var myTextFormat2:TextFormat = new TextFormat();
		myTextFormat2.font = "Kristen ITC";
		myTextFormat2.size = 20;
		myTextFormat2.color = 0xffffff;

		
				// to check name in keyboard//
		trace("i am here");
		//trace(myMaster.pageKeyboard.Text);
		player.text = myMaster.getTheText1();
		//"Name";
		player.width=300;
		player.height=40;
		player.x=45;
		player.y=630; //660
		player.visible=true;
		player.setStyle("textFormat", myTextFormat2);
		movie1.addChild(player);
		
		sLabel1.text = "Score: "
		sLabel1.width=300;
		sLabel1.height=40;
		sLabel1.x=45;
		sLabel1.y=660; //660
		sLabel1.visible=true;
		sLabel1.setStyle("textFormat", myTextFormat2);
		movie1.addChild(sLabel1);
		
		score1.text = ""+sp1;
		score1.width=300;
		score1.height=40;
		score1.x=110;
		score1.y=660; //660
		score1.visible=true;
		score1.setStyle("textFormat", myTextFormat2);
		movie1.addChild(score1);
		
		
		player2.text = myMaster.getTheText2();
		//"Name";
		player2.width=300;
		player2.height=40;
		player2.x=990;
		player2.y=80;  //50
		player2.rotationZ=180;
		player2.visible=true;
		player2.setStyle("textFormat", myTextFormat2);
		movie1.addChild(player2);
		
		sLabel2.text = "Score: "
		sLabel2.width=300;
		sLabel2.height=40;
		sLabel2.x=990;
		sLabel2.y=50; //660
		sLabel2.visible=true;
		sLabel2.setStyle("textFormat", myTextFormat2);
		sLabel2.rotationZ=180;
		movie1.addChild(sLabel2);
		
		score2.text = ""+sp2;
		score2.width=300;
		score2.height=40;
		score2.x=925;
		score2.y=50; //660
		score2.visible=true;
		score2.rotationZ=180;
		score2.setStyle("textFormat", myTextFormat2);
		movie1.addChild(score2);
		
		
		
		loadimages();
		loadimages2();
		
		right.load(new URLRequest("correct1.png"));
		right.visible=false;
		//movie1.addChild(right);
		
		wrong.load(new URLRequest("error1copy.png"));
		wrong.visible=false;
		//movie1.addChild(wrong);
		
		//addimages();
		
		}
		
		function loadimages()
		{
			var i:int=0;
			for(i=0; i<iLoaders.length; i++)
			{
				iLoaders[i] = new Loader();
				iLoaders[i].contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadImg);
				iLoaders[i].load(new URLRequest(pics[i]));
			}
		}
	
		public function moveTip2(evt:Event):void
		{
			
			
			mainLoader2.addEventListener(TouchEvent.CLICK,downEvent);
			var newEvent3:TouchEvent = new TouchEvent(TouchEvent.CLICK);
			mainLoader2.dispatchEvent(newEvent3);
			//dispatchEvent(new MouseEvent(MouseEvent.DOWN));
			
			 
		}
		
		public function moveTip3(evt:Event):void
		{
			
			
			mainLoader5.addEventListener(TouchEvent.CLICK,downEvent);
			var newEvent3:TouchEvent = new TouchEvent(TouchEvent.CLICK);
			mainLoader5.dispatchEvent(newEvent3);
			//dispatchEvent(new MouseEvent(MouseEvent.DOWN));
			
			 
		}
		
		public function showTips(e:Event):void 
		{ 
		//mainLoader= new Loader();
			skip2=false;
		
			var url = new URLRequest("example4shapes.swf"); 
			mainLoader.load(url);
			mainLoader.y=520;
			mainLoader.x=840;
			movie1.addChild(mainLoader);
			
			
			skipp.label="Skip All Tips";
			skipp.addEventListener(TouchEvent.MOUSE_DOWN, skip3); 
			skipp.y=664;
			skipp.x=858;
			skipp.width=130;
			skipp.name="tip1";
			skipp.visible=true;
			movie1.addChild(skipp);
			
			//mainLoader= new Loader();
			var url1 = new URLRequest("example2shapes.swf"); 
			mainLoader2.load(url1);
			mainLoader2.y=520;
			mainLoader2.x=840;
			mainLoader2.visible=false;
			movie1.addChild(mainLoader2);
			mainLoader2.addEventListener(TouchEvent.MOUSE_DOWN,moveTip2);
			
			skipp2.label="Skip All Tips";
			//skipp2.addEventListener(TouchEvent.MOUSE_DOWN, skip4); 
			skipp2.y=675;
			skipp2.x=862;
			skipp2.width=130;
			skipp2.name="tip3";
			skipp2.visible=false;
			movie1.addChild(skipp2);
			
			//mainLoader= new Loader();
			var url2 = new URLRequest("example3shapes.swf"); 
			mainLoader1.load(url2);
			mainLoader1.y=480;
			mainLoader1.x=840;
			mainLoader1.visible=false;
			movie1.addChild(mainLoader1);
			
			
			skipp1.label="Skip All Tips";
			skipp1.addEventListener(TouchEvent.MOUSE_DOWN, skip4); 
			skipp1.y=675;
			skipp1.x=862;
			skipp1.width=130;
			skipp1.name="tip2";
			skipp1.visible=false;
			movie1.addChild(skipp1);
			
			buttonDone.visible=false;
		}
		
		public function showTips2(e:Event):void 
		{ 
		//mainLoader= new Loader();
			skip7=false;
		
			var url3 = new URLRequest("example4shapes2.swf"); 
			mainLoader3.load(url3);
			mainLoader3.y=200;
			mainLoader3.x=190;
			mainLoader3.rotationZ=180;
			movie1.addChild(mainLoader3);
			
			
			skipp3.label="Skip All Tips";
			skipp3.addEventListener(TouchEvent.MOUSE_DOWN, skip5); 
			skipp3.y=60;
			skipp3.x=170;
			skipp3.width=130;
			skipp3.rotationZ=180;
			skipp3.visible=true;
			skipp3.name="tip4";
			movie1.addChild(skipp3);
			
			
			//mainLoader= new Loader();
			var url4 = new URLRequest("example3shapes2.swf"); 
			mainLoader4.load(url4);
			mainLoader4.y=230;
			mainLoader4.x=170;
			mainLoader4.rotationZ=180;
			mainLoader4.visible=false;
			movie1.addChild(mainLoader4);
			
			
			skipp4.label="Skip All Tips";
			skipp4.addEventListener(TouchEvent.MOUSE_DOWN, skip6); 
			skipp4.y=30;
			skipp4.x=150;
			skipp4.width=130;
			skipp4.rotationZ=180;
			skipp4.name="tip5";
			skipp4.visible=false;
			movie1.addChild(skipp4);
			
			
			//mainLoader= new Loader();
			var url5 = new URLRequest("example2shapes2.swf"); 
			mainLoader5.load(url5);
			mainLoader5.y=210;
			mainLoader5.x=190;
			mainLoader5.rotationZ=180;
			mainLoader5.visible=false;
			movie1.addChild(mainLoader5);
			mainLoader5.addEventListener(TouchEvent.MOUSE_DOWN,moveTip3);
			
			skipp5.label="Skip All Tips";
			//skipp2.addEventListener(TouchEvent.MOUSE_DOWN, skip4); 
			skipp5.y=60;
			skipp5.x=170;
			skipp5.width=130;
			skipp5.rotationZ=180;
			skipp5.name="tip6";
			skipp5.visible=false;
			movie1.addChild(skipp5);
			
			
			buttonDone2.visible=false;
		}
		
		function onLoadImg(evt:Event):void
		{
			if(once)
			{
			var i:int=0;
			for(i=0; i<iLoaders.length; i++)
			{
			
			var bitdata:BitmapData = new BitmapData(iLoaders[i].width, iLoaders[i].height, true, 0x00000000);
			bitdata.draw(iLoaders[i], new Matrix());
		
			var bitimage:Bitmap = new Bitmap(bitdata);
		
			bmpimages[i]=new tile1();
			bmpimages[i].name=i;
	
			bmpimages[i].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages[i].downEvent);
			bmpimages[i].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);									
			bmpimages[i].doubleClickEnabled = true;
			
			bmpimages[i].addChild(bitimage);		
			movie1.addChild(bmpimages[i]);
			
			
			
			}
			
			addimages();
			//addimagesUp();
			
			}
			once=false;
		}
		
		
		function addimages()
		{
			bound.graphics.lineStyle(3,0xFFFFFF);
			bound.graphics.drawRect(200,500,624,200);
			movie1.addChild(bound);
			
			var i:int=0;
			var x1:Number = randomNumber(200,720);
			var y1:Number=550;
			var angle=0;
			var k=0;
			
			for(i=0; i<bmpimages.length; i++)
			{
				bmpimages[i].x=x1;
				bmpimages[i].y=550;
				bmpimages[i].rotationZ=angle;
				
				position[k]=bmpimages[i].x;
				k++;
				position[k]=bmpimages[i].y;
				k++;
				
				x1=randomNumber(200,720);
			}
			
			//addimagesUp();
		}
		
		
		
		function loadimages2()
		{
			var i:int=0;
			for(i=0; i<iLoaders2.length; i++)
			{
				iLoaders2[i] = new Loader();
				iLoaders2[i].contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadImg2);
				iLoaders2[i].load(new URLRequest(pics2[i]));
			}
		}
	
			
		
		function onLoadImg2(evt:Event):void
		{
			if(once2)
			{
			var i:int=0;
			for(i=0; i<iLoaders2.length; i++)
			{
			
			var bitdata2:BitmapData = new BitmapData(iLoaders2[i].width, iLoaders2[i].height, true, 0x00000000);
			bitdata2.draw(iLoaders2[i], new Matrix());
		
			var bitimage2:Bitmap = new Bitmap(bitdata2);
		
			bmpimages2[i]=new tile2();
			bmpimages2[i].name=i;
	
			bmpimages2[i].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[i].downEvent);
			bmpimages2[i].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);									
			
			bmpimages2[i].alpha=0.5;
			bmpimages2[i].doubleClickEnabled = true;
			
			
			bmpimages2[i].addChild(bitimage2);		
			movie1.addChild(bmpimages2[i]);
			
			
			
			}
				addimagesUp();
			
			}
			once2=false;
		}
		
		
		
		function addimagesUp()
		{
			bound2.graphics.lineStyle(3,0xFFFFFF);
			bound2.graphics.drawRect(200,10,624,200);
			movie1.addChild(bound2);
			
			var j:int=0;
			var x2:Number = randomNumber(200,720);
			var y2:Number=60;
			var angle2=0;
			var k2=0;
			
			for(j=0; j<bmpimages2.length; j++)
			{
				bmpimages2[j].x=x2;
				bmpimages2[j].y=y2;
				bmpimages2[j].rotationZ=angle2;
				
				position2[k2]=bmpimages2[j].x;
				k2++;
				position2[k2]=bmpimages2[j].y;
				k2++;
				
				x2=randomNumber(200,720);
			}
		}
		
		
function randomNumber(low:Number=NaN, high:Number=NaN):Number
{
  var low:Number = low;
  var high:Number = high;

  if(isNaN(low))
  {
    throw new Error("low must be defined");
  }
  if(isNaN(high))
  {
    throw new Error("high must be defined");
  }

  return Math.round(Math.random() * (high - low)) + low;
}

public function skipping (e:TouchEvent):void
{
	
	if(skipTurnFlag==0)
	{
	myTimerFlash.start();
	turn=2;
	
	var i:int=0;
				for(i=0; i<iLoaders.length;i++)
				{
					
						bmpimages[i].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages[i].downEvent);
						bmpimages[i].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
								
						bmpimages[i].alpha=0.5;
					
				}
				
				avatarP1.alpha=0.5;
				
				var j:int=0;
				for( j=0; j<iLoaders2.length;j++)
				{
						bmpimages2[j].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[j].downEvent);
						bmpimages2[j].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);					
						bmpimages2[j].alpha=1.0;
				}
				
				avatarP2.alpha=1;
				
		skipTurn1.alpha=0.5;
		skipTurn2.alpha=1;
		skipTurnFlag=1;
		//avatarP2.alpha=0.5;
	}
}

public function skipping1 (e:TouchEvent):void
{
	if(skipTurnFlag==1)
	{
	myTimerFlash2.start();
	turn=1;
	
	var i:int=0;
				for(i=0; i<iLoaders2.length;i++)
				{
					//if(i!=gIndex2)
					//{
						bmpimages2[i].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[i].downEvent);
						bmpimages2[i].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
								
						bmpimages2[i].alpha=0.5;
					//}
				}
				
	avatarP2.alpha=0.5;

	var j:int=0;
				for( j=0; j<iLoaders.length;j++)
				{
						bmpimages[j].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages[j].downEvent);
						bmpimages[j].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
											
						bmpimages[j].alpha=1.0;
				}
				
				avatarP1.alpha=1;
				
	skipTurn2.alpha=0.5;
	skipTurn1.alpha=1;
	skipTurnFlag=0;
	
	
	}
}
var entering:int=1;
function flashing (e:TimerEvent):void
{
	if(entering==7)
	{
	entering=1;
	myTimerFlash.stop();
	//return;
	}
	else if(entering%2==1)
	{
		avatarP2.alpha=0;
		myTimerFlash.start();
		entering++;
	}
	else
	{//myTimerFlash.stop();
		avatarP2.alpha=1.0;
		myTimerFlash.start();
		entering++;
	}
	
	
}

var entering2:int=1;
function flashing2 (e:TimerEvent):void
{
	if(entering2==7)
	{
	entering2=1;
	myTimerFlash2.stop();
	//return;
	}
	else if(entering2%2==1)
	{
		avatarP1.alpha=0;
		myTimerFlash2.start();
		entering2++;
	}
	else
	{//myTimerFlash.stop();
		avatarP1.alpha=1.0;
		myTimerFlash2.start();
		entering2++;
	}
	
	
}

function doubleTap(s:String, xc:int, yc:int)
{
	if(turn==1)
	{
		myTimerFlash.start();
		if(xc>40 && xc<980 && yc>245 && yc<465)
		{
			var index:int = parseInt(s);
			gIndex=index;
			backpst=index*2;
			var totalx:int=bmpimages[index].x+bmpimages[index].width;
			var totaly:int=bmpimages[index].y+bmpimages[index].height;
			
			myTimerC.addEventListener(TimerEvent.TIMER, timerListenerC);
			myTimerI.addEventListener(TimerEvent.TIMER, timerListenerI);
			
			while(bmpimages[index].rotationZ>360)
			{
				bmpimages[index].rotationZ=bmpimages[index].rotationZ-360;
			}
			var diffang:Number;
			var diffxx:Number;
			var diffyy:Number;
			diffang=Math.abs(bmpimages[index].rotationZ - iHoles[index].rotationZ);
			
			diffxx=Math.abs(bmpimages[index].x-pictures[index][0]);
			diffyy=Math.abs(bmpimages[index].y-pictures[index][1]);
		
			if(diffxx<10 && diffyy<10 && diffang<10) //index==4 && diffang<10)
			{
				bmpimages[index].x=pictures[index][0];
				bmpimages[index].y=pictures[index][1];
				
				right.x=bmpimages[index].x;
				right.y=bmpimages[index].y;
				right.visible=true;
				
				movie1.removeChild(bmpimages[index]);
				
				movie1.addChild(picsInHole[index]);
				
				
				movie1.addChild(right);
				
				if(noSound==false)
				{
				correctSound= new Sound();
				correctSound.load(new URLRequest("woho.mp3"));
				correctSound.play();
				}
				
				myTimerC.start();
				//bmpimages[index].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages[index].downEvent);
				//bmpimages[index].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);									
				
				movie1.removeChild(bmpimages2[index]);
				//bmpimages2[index].visible=false;
				
				sp1++;
				score1.text=""+sp1;
				
				pleft--;
				turn=2;
			}
			else
			{
				wrong.x=bmpimages[index].x;
				wrong.y=bmpimages[index].y;
				//wrong.rotationZ=bmpimages[index].rotationZ;
				wrong.visible=true;
				movie1.addChild(wrong);
				
				
				if(noSound==false)
				{
				errorSound= new Sound();
				errorSound.load(new URLRequest("error.mp3"));
				errorSound.play();
				}
				
				myTimerI.start();
				
				
				
				turn=2;
			}
			
		}
		
	skipTurn1.alpha=0.5;
	skipTurn2.alpha=1;
	skipTurnFlag=1;
	}
	else
	{
		myTimerFlash2.start();
		if(xc>40 && xc<980 && yc>245 && yc<465)
		{
			var index2:int = parseInt(s);
			gIndex2=index2;
			backpst2=index2*2;
			var totalx2:int=bmpimages2[index2].x+bmpimages2[index2].width;
			var totaly2:int=bmpimages2[index2].y+bmpimages2[index2].height;
			
			myTimer2C.addEventListener(TimerEvent.TIMER, timerListener2C);
			myTimer2I.addEventListener(TimerEvent.TIMER, timerListener2I);
			
			while(bmpimages2[index2].rotationZ>360)
			{
				bmpimages2[index2].rotationZ=bmpimages2[index2].rotationZ-360;
			}
			var diffang2:Number;
			var diffxx2:Number;
			var diffyy2:Number;
			
			diffang2=Math.abs(bmpimages2[index2].rotationZ - iHoles[index2].rotationZ);
			
			diffxx2=Math.abs(bmpimages2[index2].x-pictures[index2][0]);
			diffyy2=Math.abs(bmpimages2[index2].y-pictures[index2][1]);
			
			if(diffxx2<10 && diffyy2<10 && diffang2<10) //index==4 && diffang<10)
			{
				bmpimages2[index2].x=pictures[index2][0];
				bmpimages2[index2].y=pictures[index2][1];
				
				right.x=bmpimages2[index2].x;
				right.y=bmpimages2[index2].y;
				right.visible=true;
				
				movie1.removeChild(bmpimages2[index2]);
				
				movie1.addChild(picsInHole[index2]);
				
				movie1.addChild(right);
				
				if(noSound==false)
				{
				correctSound= new Sound();
				correctSound.load(new URLRequest("woho.mp3"));
				correctSound.play();
				}
				
				myTimer2C.start();
				
				bmpimages[index2].visible=false;
				
				sp2++;
				score2.text=""+sp2;
				pleft--;
				turn=1;
			}
			else
			{
				wrong.x=bmpimages2[index2].x;
				wrong.y=bmpimages2[index2].y;
				//wrong.rotationZ=bmpimages2[index2].rotationZ;
				wrong.visible=true;
				movie1.addChild(wrong);
				
				
				
				if(noSound==false)
				{
				errorSound= new Sound();
				errorSound.load(new URLRequest("error.mp3"));
				errorSound.play();
				}
				
				myTimer2I.start();
				
				
				
				turn=1;
			}
		}
	skipTurn2.alpha=0.5;
	skipTurn1.alpha=1;
	skipTurnFlag=0;
	}
}

function timerListenerC (e:TimerEvent):void
{
	right.visible=false;
	
					var i:int=0;
				for(i=0; i<iLoaders.length;i++)
				{
					//if(i!=gIndex)
					//{
						bmpimages[i].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages[i].downEvent);
						bmpimages[i].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
								
						bmpimages[i].alpha=0.5;
					//}
				}
				
				avatarP1.alpha=0.5;
				
				var j:int=0;
				for( j=0; j<iLoaders2.length;j++)
				{
						bmpimages2[j].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[j].downEvent);
						bmpimages2[j].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
											
						bmpimages2[j].alpha=1.0;
				}
				
				avatarP2.alpha=1;				

	myTimerC.stop();
	if(pleft==0)
	{
		if(sp1>sp2)
			indication=1;
		else if(sp2>sp1)
			indication=2;
		else 
			indication=0;
			
		myMaster.wellDTwo();
	}
}

function timerListenerI (e:TimerEvent):void
{
	wrong.visible=false;
	bmpimages[gIndex].x=position[backpst];
	backpst++;
	bmpimages[gIndex].y=position[backpst];
	
	
			var i:int=0;
				for(i=0; i<iLoaders.length;i++)
				{
					
						bmpimages[i].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages[i].downEvent);
						bmpimages[i].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
								
						bmpimages[i].alpha=0.5;
					
				}
				
				avatarP1.alpha=0.5;
				
				var j:int=0;
				for( j=0; j<iLoaders2.length;j++)
				{
						bmpimages2[j].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[j].downEvent);
						bmpimages2[j].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
											
						bmpimages2[j].alpha=1.0;
				}
				
				avatarP2.alpha=1;
	
	myTimerI.stop();
}

function timerListener2C (e:TimerEvent):void
{
	right.visible=false;
	var i:int=0;
				for(i=0; i<iLoaders2.length;i++)
				{
					//if(i!=gIndex2)
					//{
						bmpimages2[i].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[i].downEvent);
						bmpimages2[i].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
								
						bmpimages2[i].alpha=0.5;
					//}
				}
				
	avatarP2.alpha=0.5;

	var j:int=0;
				for( j=0; j<iLoaders.length;j++)
				{
						bmpimages[j].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages[j].downEvent);
						bmpimages[j].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
											
						bmpimages[j].alpha=1.0;
				}
				
				avatarP1.alpha=1;
				
				myTimer2C.stop();
	if(pleft==0)
	{
		if(sp1>sp2)
			indication=1;
		else if(sp2>sp1)
			indication=2;
		else 
			indication=0;
		myMaster.wellDTwo();
	}
}

function timerListener2I (e:TimerEvent):void
{
	wrong.visible=false;
	bmpimages2[gIndex2].x=position2[backpst2];
	backpst2++;
	bmpimages2[gIndex2].y=position2[backpst2];
	
			var i:int=0;
				for(i=0; i<iLoaders2.length;i++)
				{
					
						bmpimages2[i].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[i].downEvent);
						bmpimages2[i].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
								
						bmpimages2[i].alpha=0.5;
					
				}
				
				avatarP2.alpha=0.5;
				
				var j:int=0;
				for( j=0; j<iLoaders.length;j++)
				{
						bmpimages[j].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages[j].downEvent);
						bmpimages[j].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
											
						bmpimages[j].alpha=1.0;
				}
				
				avatarP1.alpha=1;
	
	myTimer2I.stop();
	
}
		
		function closeApp(event:TouchEvent):void
		{
			
			fscommand("quit");
			//System.exit(0);
		
		}
		
		public function wellDone(e:Event):void
		{
			//myMaster.goToWellDone();
		}		
		
		public function skip3(e:Event):void 
		{ 
		
			
		skip2=true; 
		movie1.removeChild(mainLoader); 
		//movie1.removeChild(mainLoader1);
		//movie1.removeChild(mainLoader2);
		skipp.visible=false;
		//skipp1.visible=false;
		movie1.removeChild(skipp);
		//movie1.removeChild(skipp1);
		
		//mainLoader.addEventListener(TouchEvent.CLICK,downEvent);
		//var newEvent3:TouchEvent = new TouchEvent(TouchEvent.CLICK);
		//mainLoader.dispatchEvent(newEvent3);
		}
		public function skip4(e:Event):void 
		{ 
		
			
		skip2=true; 
		//movie1.removeChild(mainLoader); 
		movie1.removeChild(mainLoader1);
		//movie1.removeChild(mainLoader2);
		//skipp.visible=false;
		skipp1.visible=false;
		//movie1.removeChild(skipp);
		movie1.removeChild(skipp1);
		
		//mainLoader1.addEventListener(TouchEvent.CLICK,downEvent);
		//var newEvent3:TouchEvent = new TouchEvent(TouchEvent.CLICK);
		//mainLoader1.dispatchEvent(newEvent3);
		}
		public function skip5(e:Event):void 
		{ 
		skip7=true; 
		movie1.removeChild(mainLoader3); 
		//movie1.removeChild(mainLoader1);
		//movie1.removeChild(mainLoader2);
		skipp3.visible=false; 
		//skipp1.visible=false;
		movie1.removeChild(skipp3);
		//movie1.removeChild(skipp1);
		}
		public function skip6(e:Event):void 
		{ 
		skip7=true; 
		//movie1.removeChild(mainLoader); 
		movie1.removeChild(mainLoader4);
		//movie1.removeChild(mainLoader2);
		//skipp.visible=false;
		skipp4.visible=false;
		//movie1.removeChild(skipp);
		movie1.removeChild(skipp4);
		}
		
		
		/*public function disappear(e:Event):void
		{
			skipp.visible=false;
		}
		
		public function disappear1(e:Event):void
		{
			skipp1.visible=false;
		}*/
		
		function backMethod(event:TouchEvent):void
		{
			myMaster.backToMainMenuPlayers();
		}
		
		function muteMethod(event:TouchEvent):void
		{
			if(mute.name=='unmute')   // want to pause
			{
			//myMaster.mute();
			//mute2();
			noSound=true;
			mute.load(new URLRequest(images[3]));
			mute.name='mute';
			
			}
			else   // want to play again
			{
			//unmute2();
			noSound=false;
			mute.load(new URLRequest(images[4]));	
			mute.name='unmute';
			}
		}
			
		
		
		private function drawButtonState(rgb:uint):Sprite {
		var sprite:Sprite = new Sprite();
		//sprite.graphics.lineStyle(4,0x33621E,1);
		sprite.graphics.beginFill(rgb);
		sprite.graphics.drawRoundRect(((this.stage.
		stageWidth/2)-(numButtonWidth/2)),((this.
		stage.stageHeight/2)-(numButtonHeight/2)),
		numButtonWidth,numButtonHeight,10,10);
		return sprite;
		}
		
		    function updater(e:Event):void {
            for (var i:int = 0; i < blobs.length; i++) { 
                var tuioobj:TUIOObject=TUIO.getObjectById(blobs[i].id);
 
                // if not found, then it must have died..
                if (! tuioobj) {
                    removeBlob(blobs[i].id);
                } else if (parent != null) {
 
                    lines["line"+blobs[i].id].graphics.lineTo(tuioobj.x, tuioobj.y);
                }
            }
        }
		
		 public function downEvent(e:TouchEvent):void {
            //var curPt:Point=parent.globalToLocal(new Point(e.stageX,e.stageY));
            //addBlob(e.ID, curPt.x, curPt.y);
            //e.stopPropagation();
			
			/*if(skip2==false)
			{
			//mainLoader.visible=false;
			//skipp.visible=false;
			mainLoader1.visible=true;
			skipp1.visible=true;
			}*/
			
			
			
			if(turn==1)
			{
				/*mainLoader.enabled=true;
				mainLoader1.enabled=true;
				mainLoader2.enabled=true;
				mainLoader3.enabled=false;
				mainLoader4.enabled=false;
				mainLoader5.enabled=false;
				
				skipp.enabled=true;
				skipp1.enabled=true;
				skipp2.enabled=true;
				skipp3.enabled=false;
				skipp4.enabled=false;
				skipp5.enabled=false;
				
				buttonDone.enabled=true;
				buttonDone2.enabled=false;*/
				
				if(skipp2.parent!=movie1 || skip2==true)
				{
					buttonDone.visible=true;
					//enable=true;
				}
				
				if(skip2==false)
				{
				//mainLoader.visible=false;
				//skipp.visible=false;
				if(skipp.parent==movie1)
				{
				movie1.removeChild(mainLoader);
				skipp.visible=false;
				//skipp1.visible=false;
				movie1.removeChild(skipp);
				}
				
				mainLoader1.visible=true;
				skipp1.visible=true;
				}
				
				//if(e.currentTarget.x>200 && e.currentTarget.x<824 && e.currentTarget.y>500 && e.currentTarget.y<700)
				//{
					var index:int = parseInt(e.currentTarget.name);
					if(e.currentTarget.x<200 || e.currentTarget.x>824 || e.currentTarget.y<500 || e.currentTarget.y>700) //|| moveAgain==false)
					{
						
						if(skip2==false)
						{
							if(skipp1.parent==movie1)
							{
								movie1.removeChild(mainLoader1);
								skipp1.visible=false;
								movie1.removeChild(skipp1);
							}
							mainLoader2.visible=true;
						}
						
						trace("dimming");
						var i:int=0;
						for(i=0; i<iLoaders.length;i++)
						{
							if(i!=index)
							{
								bmpimages[i].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages[i].downEvent);
								bmpimages[i].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
								
								bmpimages[i].alpha=0.5;
							}
						}
					}
						else
						{
							trace("not dimming" + e.currentTarget.x + "  " + e.currentTarget.y);
							var j:int=0;
							for( j=0; j<iLoaders.length;j++)
							{
								if(j!=index)
								{
									bmpimages[j].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages[j].downEvent);
									bmpimages[j].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
											
									bmpimages[j].alpha=1.0;
								}
							}
						}
				//}
			
			
			}
			else
			{
				
				
				/*mainLoader3.enabled=true;
				mainLoader4.enabled=true;
				mainLoader5.enabled=true;
				mainLoader.enabled=false;
				mainLoader1.enabled=false;
				mainLoader2.enabled=false;
				
				skipp3.enabled=true;
				skipp4.enabled=true;
				skipp5.enabled=true;
				skipp.enabled=false;
				skipp1.enabled=false;
				skipp2.enabled=false;
				
				buttonDone2.enabled=true;
				buttonDone.enabled=false;*/
				
				if(skipp5.parent!=movie1 || skip7==true)
				{
					buttonDone2.visible=true;
					//enable=true;
				}
				
				if(skip7==false)
				{
				//mainLoader.visible=false;
				//skipp.visible=false;
				if(skipp3.parent==movie1)
				{
				movie1.removeChild(mainLoader3);
				skipp3.visible=false;
				//skipp1.visible=false;
				movie1.removeChild(skipp3);
				}
				
				mainLoader4.visible=true;
				skipp4.visible=true;
				}
				
				
				var index2:int = parseInt(e.currentTarget.name);
					if(e.currentTarget.x<200 || e.currentTarget.x>824 || e.currentTarget.y<10 || e.currentTarget.y>210) //|| moveAgain==false)
					{
						
						if(skip7==false)
						{
							if(skipp4.parent==movie1)
							{
								movie1.removeChild(mainLoader4);
								skipp4.visible=false;
								movie1.removeChild(skipp4);
							}
							mainLoader5.visible=true;
						}
						
						var i:int=0;
						for(i=0; i<iLoaders2.length;i++)
						{
							if(i!=index2)
							{
								bmpimages2[i].removeEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[i].downEvent);
								bmpimages2[i].removeEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
								
								bmpimages2[i].alpha=0.5;
							}
						}
					}
					
						else
						{
							trace("not dimming" + e.currentTarget.x + "  " + e.currentTarget.y);
							var j:int=0;
							for( j=0; j<iLoaders2.length;j++)
							{
								if(j!=index2)
								{
									bmpimages2[j].addEventListener(TouchEvent.MOUSE_DOWN, bmpimages2[j].downEvent);
									bmpimages2[j].addEventListener(TouchEvent.MOUSE_DOWN, this.downEvent);
											
									bmpimages2[j].alpha=1.0;
								}
							}
						}
			}
			
			if(e.stageX == 0 && e.stageY == 0)
				return;			
			
			var curPt:Point = parent.globalToLocal(new Point(e.stageX, e.stageY));									
			

			addBlob(e.ID, curPt.x, curPt.y);
			
			if(bringToFront)
				this.parent.setChildIndex(this, this.parent.numChildren-1);
			
				if(mouseSelection)
				{
					//this.alpha=0.5;				
				}
			
			//DoubleTap Gesture
			var tuioobj:TUIOObject = TUIO.getObjectById(e.ID);
			var localPt:Point = globalToLocal(new Point(tuioobj.x, tuioobj.y));
			
			xdist = localPt.x - oldX;
			ydist = localPt.y - oldY;			
			distance = Math.sqrt(xdist*xdist+ydist*ydist);
			oldX = localPt.x;
			oldY = localPt.y;		
			
			if (parent.hitTestPoint(localPt.x,localPt.y) && distance <= clickRadius) {

				if (lastClick == 0) {
					lastClick = getTimer();
					trace("last click");
					trace(lastClick);
					identity=e.ID;
					doubleT.start();
					FirstPoint= parent.globalToLocal(new Point(e.stageX, e.stageY));
				} 
				else
				{
					SecondPoint= parent.globalToLocal(new Point(e.stageX, e.stageY));
					
					if(doubleT.running==true)
					{
						newTouchItem = TUIO.returnBlobs();
						var distanceBetween:Number=Point.distance(FirstPoint, SecondPoint);
						
						if(identity!=e.ID  && newTouchItem.length==1 && distanceBetween<10)
						{
							trace("The number of active blobs");
							trace(newTouchItem.length);
							lastClick = 0;
							trace("Double Tap");
							
							
							doubleTap(e.currentTarget.name, e.currentTarget.x, e.currentTarget.y);//perform doubleTap Function	
							
						}
						
					}
					else
					{
						lastClick = 0;
					}
					doubleT.stop();
				}
				
			}
			
			
        }
		
		function clickHandler(evtObj:MouseEvent){
		trace("The " + evtObj.target.label + " button was clicked");
		}
 
        // When a finger stops touching, call removeBlob
        public function upEvent(e:TouchEvent):void {
            removeBlob(e.ID);
            e.stopPropagation();
        }
 
        // This takes the sent ID, x,y and puts it all in the blobs array
        // It then creats a new sprite, and sets the starting loc of the line
        // The line is put in an array called lines, so it can be called over and over by name
        // if the lines did not have unique names you could only draw one line at a time
        // so each line is named in the array after the id of the blob (EG line1280)
        function addBlob(id:Number, origX:Number, origY:Number):void {
            blobs.push( {id: id, origX: origX, origY: origY, myOrigX: x, myOrigY:y} );
 
            var line:Sprite = new Sprite();
            lines["line"+id] = line;
            //lines["line"+id].graphics.lineStyle(thickness, color); //<-- config above
            lines["line"+id].graphics.moveTo(origX, origY); //starting point of line to be drawn
            addChild(lines["line"+id]); // add line to stage
        }
 
        // when called, this function removes the blobs from the array
        // cycles through the blobs array until the blob is found by its ID, then it is removed.
        function removeBlob(id:Number):void {
            for (var i=0; i < blobs.length; i++) {
                if (blobs[i].id==id) {
                    blobs.splice(i, 1);
                    return;
                }
            }
        }
 
    }
}
		
		